//
//  LPShowNoDataManager.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/8/18.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPShowNoDataManager.h"

@implementation LPShowNoDataManager

+ (LPShowNoDataManager *)showNoDataManager
{
    static LPShowNoDataManager *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedAccountManagerInstance = [[self alloc] init];
    });
    return sharedAccountManagerInstance;
}


/**
 展示无数据占位图
 
 @param emptyViewType 无数据占位图的类型
 */
- (void)showEmptyViewWithView:(UIView *)view  Type:(NSInteger)emptyViewType{
    
    // 如果已经展示无数据占位图，先移除
    if (_noContentView) {
        [_noContentView removeFromSuperview];
        _noContentView = nil;
    }
    
    //------- 再创建 -------//
    _noContentView = [[NoContentView alloc]initWithFrame:CGRectMake(0, 0, view.width, view.height)];
    [view addSubview:_noContentView];
    _noContentView.type = emptyViewType;
    
    /**  这是网络错误点击重新加载数据  */
    if (emptyViewType == 0) {
        //------- 添加单击手势 -------//
        [_noContentView.bottomLabel addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(noContentViewDidTaped:)]];
    }
   
}


- (void)showEmptyViewWithErrorView:(UIView *)view{
    
    // 如果已经展示无数据占位图，先移除
    if (_noContentView) {
        [_noContentView removeFromSuperview];
        _noContentView = nil;
    }
    
    //------- 再创建 -------//
    _noContentView = [[NoContentView alloc]initWithFrame:CGRectMake(0, 64, view.width, [UIScreen zj_screenHeight] - 64)];
    [view addSubview:_noContentView];
    _noContentView.type = 0;
    
    /**  这是网络错误点击重新加载数据  */
   
    //------- 添加单击手势 -------//
    [_noContentView.bottomLabel addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(noContentViewDidTaped:)]];
    
    
}


/* 移除无数据占位图 */
- (void)removeEmptyView{
    [_noContentView removeFromSuperview];
    _noContentView = nil;
}

// 无数据占位图点击
- (void)noContentViewDidTaped:(NoContentView *)noContentView{
    if (self.noContentViewTapedBlock)
    {
        self.noContentViewTapedBlock();//调用回调函数
    }
}

@end
